using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.SceneManagement;

public class GameTimer : MonoBehaviour
{
    public TMP_Text text;
    private string forward = "Time - ";
    public float timer;
    void Start()
    {
        text = GetComponent<TMP_Text>( );
        timer = 0;
    }

    
    void Update()
    {
        if ( SceneManager.GetActiveScene().buildIndex > 1 )
        {
            timer = GameManager.instance.GetFinishTimer( );
        }
        else
        {
            timer = GameManager.instance.GetTimer( );
        }
        
        
        if ( timer < 0.01f )
        {
            text.text = forward + "00.00";
        }
        else if (timer < 10 )
        {
            text.text = forward + "0" + timer.ToString( ).Substring( 0 ,4);
        }
        else if(timer < 100)
        {
            text.text = forward + timer.ToString( ).Substring( 0,5 );
        }
        else
        {
            text.text = forward + timer.ToString( ).Substring( 0,6 );
        }
        
    }
}
